package com.future.wxapp.pedometer.controller;

import com.alibaba.fastjson.JSONObject;
import com.future.wxapp.common.domain.JsonResult;
import com.future.wxapp.common.util.ResponseUtil;
import com.future.wxapp.pedometer.dao.TypeDao;
import com.future.wxapp.pedometer.service.ShowDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
public class ShowDataController {
    @Autowired
    private ShowDataService showDataService;
    @Autowired
    private TypeDao typeDao;

    @GetMapping()
    @ResponseBody
    public JsonResult salesVolume() {
        return ResponseUtil.ok();
    }

    @GetMapping("countByType")
    @ResponseBody
    public JsonResult countByType() {
        List<JSONObject> data = showDataService.countByType();
        JsonResult result = ResponseUtil.ok();
        result.setData(data);
        return result;
    }

    @GetMapping("indexShowData")
    @ResponseBody
    public JsonResult annualSales() {
        Double annualSales = showDataService.annualSales();
        Integer totalChicken = showDataService.totalChicken();
        Long totalStep = showDataService.totalStep();
        JsonResult result = ResponseUtil.ok();
        Map<String, Object> data = new HashMap<>();
        data.put("annualSales", annualSales);
        data.put("totalChicken", totalChicken);
        data.put("totalStep", totalStep);
        result.setData(data);
        return result;
    }

    @GetMapping("typeSalesVolume")
    @ResponseBody
    public JsonResult typeSalesVolume() {
        List<JSONObject> data = showDataService.typeSalesVolume();
        JsonResult result = ResponseUtil.ok();
        result.setData(data);
        return result;
    }

    @GetMapping("stepCountByType")
    @ResponseBody
    public JsonResult stepCountByType() {
        List<JSONObject> data = showDataService.stepCountByType();
        JsonResult result = ResponseUtil.ok();
        result.setData(data);
        return result;
    }

    @GetMapping("salesStatistics")
    @ResponseBody
    public JsonResult salesStatistics() {
        List<JSONObject> data = showDataService.salesStatistics();
        JsonResult result = ResponseUtil.ok();
        result.setData(data);
        return result;
    }

    @GetMapping("typeSaleStatistics")
    @ResponseBody
    public JsonResult typeSaleStatistics() {
        List<JSONObject> data = showDataService.typeSaleStatistics();
        JsonResult result = ResponseUtil.ok();
        result.setData(data);
        return result;
    }

    @GetMapping("monthOldSale")
    @ResponseBody
    public JsonResult monthOldSale() {
        List<JSONObject> data = showDataService.monthOldSale();
        JsonResult result = ResponseUtil.ok();
        result.setData(data);
        return result;
    }

}
